//
//  LoginViewController.m
//  IGOtest
//
//  Created by administrator on 14-2-24.
//  Copyright (c) 2014年 administrator. All rights reserved.
//

#import "LoginViewController.h"
#import "HomeViewController.h"
#import "RegisterViewController.h"
#define KIPLogin @"http://10.207.1.23:8888/user/regist.php"
#import "AppDelegate.h"
@interface LoginViewController ()
{
    AppDelegate *del;
}

@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    del = [[UIApplication sharedApplication]delegate ];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)denglu:(UIButton *)sender {
    NSString *loginstr=[NSString stringWithFormat:@"?username1=%@&password1=%@",self.usernametxt.text,self.passwordtxt.text];
    NSURL *url=[NSURL URLWithString:[KIPLogin stringByAppendingString:loginstr]];
    NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url];
    NSError *error=nil;
    NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
//    NSString *response=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding ];
//    NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
    if ([str isEqualToString:@"success"] || [str isEqualToString:@""]) {
        NSLog(@"===%@",str);
        UIAlertView *alter=[[UIAlertView alloc]initWithTitle:@"提示" message:@"登录成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alter show];
        del.username = self.usernametxt.text;
        del.password =self.passwordtxt.text;


    }
    else
    {
        UIAlertView *alter=[[UIAlertView alloc]initWithTitle:@"提示" message:@"登录失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alter show];
        
        NSLog(@"===%@",str);
   }
    
}

- (IBAction)zhuce:(UIButton *)sender {
    RegisterViewController *registers =[[RegisterViewController alloc]initWithNibName:@"RegisterViewController" bundle:nil ];
    [self presentViewController:registers animated:YES completion:nil];
}

- (IBAction)returnhome:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
